package com.example.feature.demo.controller;

import com.example.feature.demo.service.RateLimiterService;
import com.example.feature.demo.service.SnowflakeService;
import com.example.feature.demo.util.redis.snowflake.IdGrneratorFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * MyController
 *
 * @author zhouxianfeng
 * @date 2021-4-28
 */
@RestController
@RequestMapping("/my")
public class MyController {

    @Autowired
    SnowflakeService snowflakeService;

    @Autowired
    private RateLimiterService rateLimiterService;

    @Autowired
    private IdGrneratorFactory idGrneratorFactory;

    @GetMapping("/test")
    public Long test() {
        return snowflakeService.getId();
    }

    @GetMapping("/test1")
    public Long test1() {
        return 111L;
    }

    @GetMapping("/test2")
    public Long test2() {
        return 111L;
    }

    @GetMapping("/testRateLimiter")
    public Long testRateLimiter() {
        rateLimiterService.sendMsg("18576666986");
        return 111L;
    }

    @GetMapping("/getId")
    public Long testGetId(String name) {
        return idGrneratorFactory.nextId(name);
    }
}
